<!-- 获取分类数据 -->
<script setup>
import { ref } from 'vue'
import { artGetChannelsService } from '../../../api/article'

defineProps({
  modelValue: {
    type: [Number, String]
  },
  width: {
    type: String
  }
})
const emit = defineEmits(['update:modelValue', 'categorys'])

const categorys = ref([])
// 回显分类
const categoryList = async () => {
  const result = await artGetChannelsService()
  categorys.value = result.data.data
  emit('categorys', categorys.value)
  // console.log(result.data)
  // 处理数据,给数据模型扩展一个属性categoryName,分类名称
}
categoryList()
</script>

<template>
  <!-- el-option下面一旦修改了，触发@update:modelValue="emit('update:modelValue', $event)"事件 子传父 -->
  <el-select
    placeholder="请选择"
    :modelValue="modelValue"
    @update:modelValue="emit('update:modelValue', $event)"
    :style="{ width }"
  >
    <el-option
      v-for="category in categorys"
      :key="category.id"
      :label="category.categoryName"
      :value="category.id"
    >
    </el-option>
  </el-select>
</template>

<style></style>
